package edu.dayu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.dayu.pojo.Person;
import edu.dayu.service.PersonService;
import edu.dayu.mapper.PersonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 86134
* @description 针对表【person】的数据库操作Service实现
* @createDate 2023-03-11 11:25:00
*/
@Service
@CacheConfig(keyGenerator = "keyGenerator")
public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person>
    implements PersonService{

    @Autowired
    private PersonMapper personMapper;

    @Cacheable(value = "person",key = "'list'")
    @Override
    public List<Person> queryPerson(String name) {
        System.out.println("查数据库");
        List<Person> personList = personMapper.selectList(new QueryWrapper<Person>().eq("name", name));
        return personList;
    }

    @CacheEvict(value = "person",key = "'list'")
    @Override
    public Integer addPerson(String name, Integer age) {
        Person person = new Person();
        person.setName(name);
        person.setAge(age);
        return personMapper.insert(person);
    }

}




